/******************************************************************************
 * Title:     Younker Web Application Framework
 * Copyright: Copyright (c) 2004
 * Company:   YounkerSoft
 * Author:    Xiao Jian
 * Version:   2.0
 *****************************************************************************/
package com.younker.waf.db;

import java.io.Reader;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.ibatis.common.resources.Resources;

public class IBatisConfig
{

        private static SqlMapClient sqlMap = null;
        private static final Log log = LogFactory.getLog(IBatisConfig.class);

        public static void buildConfig(String sqlmapUrl)
        {
                try
                {
                        Reader reader = Resources.getUrlAsReader(sqlmapUrl);
                        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
                        log.info("iBatis SqlMap is successfully parsed :" + sqlmapUrl);
                } catch (Exception e)
                {
                        log.fatal("Error initializing sqlMapConfig class. Cause: ",
                                        e);
                }
        }

        public static SqlMapClient getSqlMapInstance()
        {
                return sqlMap;
        }

}
